package zuochengyun.sort;

import com.sun.tools.javac.Main;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import java.awt.image.Kernel;

public class SORT {
    private static void swap(int[] arr, int mixValue, int j) {
        int temp = arr[mixValue];
        arr[mixValue] = arr[j];
        arr[j] = temp;
    }

    public  static void selectSort(int arr[]){
        int len = arr.length;
        for (int i = 0; i < len; i++) {
            int mixValue = i;
            for (int j = i + 1; j < len; j++) {
                if(arr[mixValue]>arr[j]){
                    mixValue = j;
                }
            }
            swap(arr, mixValue, i);
        }
    }
    public  static void bubbleSort(int arr[]){
        if(arr==null||arr.length<2){
            return;
        }
        int len = arr.length;
        for (int i = len-1; i >=0; i--) {
            // 0 1
            // 1 2
            // n-1 n
            int mixValue = i;
            for (int j = 0 ; j < i; j++) {
                if(arr[j]>arr[j+1]){
                    swap(arr, j, j+1);
                }

            }
        }
    }

    public static void main(String[] args) {
        int [] arr= {6,3,5,8,2,1,1,4,9,2,4};
        bubbleSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
